package com.bobo.listener;

import com.bobo.entity.VoucherOrder;
import com.bobo.websocket.WebSocketServer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@Slf4j
public class wsListener {

    private final WebSocketServer webSocketServer;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "order.ws",durable = "true"),
            exchange = @Exchange(name = "order.direct",durable = "true"),
            key = "pay.success"
    ))
    public void ws(String json) {
        //异步发送Json
        webSocketServer.sendToAllClient(json);
    }
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "order.ws",durable = "true"),
            exchange = @Exchange(name = "order.direct",durable = "true"),
            key = "reminder"
    ))
    public void reminder(String json) {
        webSocketServer.sendToAllClient(json);
    }

}
